USE SAS
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_ACTIVITYTASK_TR_ACTIVITYTYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_ACTIVITYTASK]'))
ALTER TABLE [dbo].[TR_ACTIVITYTASK] DROP CONSTRAINT [FK_TR_ACTIVITYTASK_TR_ACTIVITYTYPE]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_ACTIVITYTASK_TR_STATUS]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_ACTIVITYTASK]'))
ALTER TABLE [dbo].[TR_ACTIVITYTASK] DROP CONSTRAINT [FK_TR_ACTIVITYTASK_TR_STATUS]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_ADDRESS_TR_ADDRESSTYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_ADDRESS]'))
ALTER TABLE [dbo].[TR_ADDRESS] DROP CONSTRAINT [FK_TR_ADDRESS_TR_ADDRESSTYPE]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_ADDRESS_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_ADDRESS]'))
ALTER TABLE [dbo].[TR_ADDRESS] DROP CONSTRAINT [FK_TR_ADDRESS_TR_PARTNER]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_ADDRESS_TR_STATES]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_ADDRESS]'))
ALTER TABLE [dbo].[TR_ADDRESS] DROP CONSTRAINT [FK_TR_ADDRESS_TR_STATES]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_COMMUNICATION_TR_ADDRESS]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_COMMUNICATION]'))
ALTER TABLE [dbo].[TR_COMMUNICATION] DROP CONSTRAINT [FK_TR_COMMUNICATION_TR_ADDRESS]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_CONTACT_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_CONTACT]'))
ALTER TABLE [dbo].[TR_CONTACT] DROP CONSTRAINT [FK_TR_CONTACT_TR_PARTNER]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_EMAIL_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_EMAIL]'))
ALTER TABLE [dbo].[TR_EMAIL] DROP CONSTRAINT [FK_TR_EMAIL_TR_PARTNER]
GO
--IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_NOTE_TR_ACTIVITYTASK]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_NOTE]'))
--ALTER TABLE [dbo].[TR_NOTE] DROP CONSTRAINT [FK_TR_NOTE_TR_ACTIVITYTASK]
--GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_NOTE_TR_NOTETYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_NOTE]'))
ALTER TABLE [dbo].[TR_NOTE] DROP CONSTRAINT [FK_TR_NOTE_TR_NOTETYPE]
GO
--IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_NOTE_TR_OPPORTUNITYH]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_NOTE]'))
--ALTER TABLE [dbo].[TR_NOTE] DROP CONSTRAINT [FK_TR_NOTE_TR_OPPORTUNITYH]
--GO
--IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_NOTE_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_NOTE]'))
--ALTER TABLE [dbo].[TR_NOTE] DROP CONSTRAINT [FK_TR_NOTE_TR_PARTNER]
--GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYH_TR_OPPREFERRAL]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYH]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYH] DROP CONSTRAINT [FK_TR_OPPORTUNITYH_TR_OPPREFERRAL]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYH_TR_OPPSTAGE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYH]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYH] DROP CONSTRAINT [FK_TR_OPPORTUNITYH_TR_OPPSTAGE]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYH_TR_OPPTYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYH]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYH] DROP CONSTRAINT [FK_TR_OPPORTUNITYH_TR_OPPTYPE]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYH_TR_STATUS]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYH]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYH] DROP CONSTRAINT [FK_TR_OPPORTUNITYH_TR_STATUS]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYI_TR_OPPORTUNITYH]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYI]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYI] DROP CONSTRAINT [FK_TR_OPPORTUNITYI_TR_OPPORTUNITYH]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYI_TR_PRODUCT]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYI]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYI] DROP CONSTRAINT [FK_TR_OPPORTUNITYI_TR_PRODUCT]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_ACCTGROUP]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER] DROP CONSTRAINT [FK_TR_PARTNER_TR_ACCTGROUP]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_DATAORIGIN]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER] DROP CONSTRAINT [FK_TR_PARTNER_TR_DATAORIGIN]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_PARTNERCATEGORY]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER] DROP CONSTRAINT [FK_TR_PARTNER_TR_PARTNERCATEGORY]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_PARTNERDIVISION]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER] DROP CONSTRAINT [FK_TR_PARTNER_TR_PARTNERDIVISION]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_PARTNERTYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER] DROP CONSTRAINT [FK_TR_PARTNER_TR_PARTNERTYPE]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_VERTICAL]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER] DROP CONSTRAINT [FK_TR_PARTNER_TR_VERTICAL]
GO
--IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_RELATIONSHIPS_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_RELATIONSHIPS]'))
--ALTER TABLE [dbo].[TR_RELATIONSHIPS] DROP CONSTRAINT [FK_TR_RELATIONSHIPS_TR_PARTNER]
--GO
--IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_RELATIONSHIPS_TR_PARTNER1]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_RELATIONSHIPS]'))
--ALTER TABLE [dbo].[TR_RELATIONSHIPS] DROP CONSTRAINT [FK_TR_RELATIONSHIPS_TR_PARTNER1]
--GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_RELATIONSHIPS_TR_RELATIONTYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_RELATIONSHIPS]'))
ALTER TABLE [dbo].[TR_RELATIONSHIPS] DROP CONSTRAINT [FK_TR_RELATIONSHIPS_TR_RELATIONTYPE]
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_USER_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_USER]'))
ALTER TABLE [dbo].[TR_USER] DROP CONSTRAINT [FK_TR_USER_TR_PARTNER]
GO
/****** Object:  Table [dbo].[TR_ACCTGROUP]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_ACCTGROUP]') AND type in (N'U'))
DROP TABLE [dbo].[TR_ACCTGROUP]
GO
/****** Object:  Table [dbo].[TR_ACTIVITYTASK]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_ACTIVITYTASK]') AND type in (N'U'))
DROP TABLE [dbo].[TR_ACTIVITYTASK]
GO
/****** Object:  Table [dbo].[TR_ACTIVITYTYPE]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_ACTIVITYTYPE]') AND type in (N'U'))
DROP TABLE [dbo].[TR_ACTIVITYTYPE]
GO
/****** Object:  Table [dbo].[TR_ADDRESS]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_ADDRESS]') AND type in (N'U'))
DROP TABLE [dbo].[TR_ADDRESS]
GO
/****** Object:  Table [dbo].[TR_ADDRESSTYPE]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_ADDRESSTYPE]') AND type in (N'U'))
DROP TABLE [dbo].[TR_ADDRESSTYPE]
GO
/****** Object:  Table [dbo].[TR_COMMUNICATION]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_COMMUNICATION]') AND type in (N'U'))
DROP TABLE [dbo].[TR_COMMUNICATION]
GO
/****** Object:  Table [dbo].[TR_CONTACT]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_CONTACT]') AND type in (N'U'))
DROP TABLE [dbo].[TR_CONTACT]
GO
/****** Object:  Table [dbo].[TR_DATAORIGIN]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_DATAORIGIN]') AND type in (N'U'))
DROP TABLE [dbo].[TR_DATAORIGIN]
GO
/****** Object:  Table [dbo].[TR_EMAIL]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_EMAIL]') AND type in (N'U'))
DROP TABLE [dbo].[TR_EMAIL]
GO
/****** Object:  Table [dbo].[TR_NOTE]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_NOTE]') AND type in (N'U'))
DROP TABLE [dbo].[TR_NOTE]
GO
/****** Object:  Table [dbo].[TR_NOTETYPE]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_NOTETYPE]') AND type in (N'U'))
DROP TABLE [dbo].[TR_NOTETYPE]
GO
/****** Object:  Table [dbo].[TR_OPPORTUNITYH]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYH]') AND type in (N'U'))
DROP TABLE [dbo].[TR_OPPORTUNITYH]
GO
/****** Object:  Table [dbo].[TR_OPPORTUNITYI]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYI]') AND type in (N'U'))
DROP TABLE [dbo].[TR_OPPORTUNITYI]
GO
/****** Object:  Table [dbo].[TR_OPPREFERRAL]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_OPPREFERRAL]') AND type in (N'U'))
DROP TABLE [dbo].[TR_OPPREFERRAL]
GO
/****** Object:  Table [dbo].[TR_OPPSTAGE]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_OPPSTAGE]') AND type in (N'U'))
DROP TABLE [dbo].[TR_OPPSTAGE]
GO
/****** Object:  Table [dbo].[TR_OPPTYPE]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_OPPTYPE]') AND type in (N'U'))
DROP TABLE [dbo].[TR_OPPTYPE]
GO
/****** Object:  Table [dbo].[TR_PARTNER]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]') AND type in (N'U'))
DROP TABLE [dbo].[TR_PARTNER]
GO
/****** Object:  Table [dbo].[TR_PARTNERCATEGORY]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_PARTNERCATEGORY]') AND type in (N'U'))
DROP TABLE [dbo].[TR_PARTNERCATEGORY]
GO
/****** Object:  Table [dbo].[TR_PARTNERDIVISION]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_PARTNERDIVISION]') AND type in (N'U'))
DROP TABLE [dbo].[TR_PARTNERDIVISION]
GO
/****** Object:  Table [dbo].[TR_PARTNERTYPE]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_PARTNERTYPE]') AND type in (N'U'))
DROP TABLE [dbo].[TR_PARTNERTYPE]
GO
/****** Object:  Table [dbo].[TR_PRODUCT]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_PRODUCT]') AND type in (N'U'))
DROP TABLE [dbo].[TR_PRODUCT]
GO
/****** Object:  Table [dbo].[TR_RELATIONSHIPS]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_RELATIONSHIPS]') AND type in (N'U'))
DROP TABLE [dbo].[TR_RELATIONSHIPS]
GO
/****** Object:  Table [dbo].[TR_RELATIONTYPE]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_RELATIONTYPE]') AND type in (N'U'))
DROP TABLE [dbo].[TR_RELATIONTYPE]
GO
/****** Object:  Table [dbo].[TR_STATES]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_STATES]') AND type in (N'U'))
DROP TABLE [dbo].[TR_STATES]
GO
/****** Object:  Table [dbo].[TR_STATUS]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_STATUS]') AND type in (N'U'))
DROP TABLE [dbo].[TR_STATUS]
GO
/****** Object:  Table [dbo].[TR_USER]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_USER]') AND type in (N'U'))
DROP TABLE [dbo].[TR_USER]
GO
/****** Object:  Table [dbo].[TR_VERTICAL]    Script Date: 04/24/2009 23:40:06 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_VERTICAL]') AND type in (N'U'))
DROP TABLE [dbo].[TR_VERTICAL]
GO
/****** Object:  Table [dbo].[TR_ACCTGROUP]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_ACCTGROUP]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_ACCTGROUP](
	[AccountGroup] [int] NOT NULL,
	[GroupDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_ACCTGROUP] PRIMARY KEY CLUSTERED 
(
	[AccountGroup] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_ACTIVITYTASK]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_ACTIVITYTASK]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_ACTIVITYTASK](
	[ActivityTaskId] [int] NOT NULL,
	[ActivityTaskGuid] [uniqueidentifier] NOT NULL,
	[Description] [varchar](200) NOT NULL,
	[ActivityType] [int] NOT NULL,
	[Status] [int] NOT NULL,
	[StartDate] [datetime] NOT NULL,
	[EndDate] [datetime] NOT NULL,
	[IsTask] [bit] NULL,
 CONSTRAINT [PK_TR_ACTIVITYTASK_1] PRIMARY KEY CLUSTERED 
(
	[ActivityTaskGuid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_ACTIVITYTYPE]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_ACTIVITYTYPE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_ACTIVITYTYPE](
	[ActivityType] [int] NOT NULL,
	[TypeDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_ACTIVITYTYPE] PRIMARY KEY CLUSTERED 
(
	[ActivityType] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_ADDRESS]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_ADDRESS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_ADDRESS](
	[AddressNo] [int] NOT NULL,
	[AddressType] [int] NOT NULL,
	[Street1] [varchar](200) NOT NULL,
	[Street2] [varchar](200) NULL,
	[City] [varchar](50) NOT NULL,
	[State] [varchar](10) NOT NULL,
	[Zip] [varchar](10) NULL,
	[CreatedBy] [int] NOT NULL,
	[CreateDate] [datetime] NOT NULL,
	[ChangedBy] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[AddressGuid] [uniqueidentifier] NOT NULL,
	[PartnerGuid] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_TR_ADDRESS] PRIMARY KEY CLUSTERED 
(
	[AddressGuid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_ADDRESSTYPE]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_ADDRESSTYPE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_ADDRESSTYPE](
	[AddressType] [int] NOT NULL,
	[TypeDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_ADDRESSTYPE] PRIMARY KEY CLUSTERED 
(
	[AddressType] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_COMMUNICATION]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_COMMUNICATION]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_COMMUNICATION](
	[CommunicationId] [int] NOT NULL,
	[Phone] [varchar](20) NULL,
	[PhoneExtension] [varchar](10) NULL,
	[Fax] [varchar](20) NULL,
	[CellPhone] [varchar](20) NULL,
	[CreatedBy] [int] NOT NULL,
	[CreateDate] [datetime] NOT NULL,
	[ChangedBy] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[PartnerGuid] [uniqueidentifier] NOT NULL,
	[AddressGuid] [uniqueidentifier] NOT NULL,
 CONSTRAINT [pk_communication] PRIMARY KEY CLUSTERED 
(
	[CommunicationId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_CONTACT]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_CONTACT]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_CONTACT](
	[PartnerNo] [int] NOT NULL,
	[JobTitle] [varchar](100) NULL,
	[Department] [varchar](100) NULL,
	[CreatedBy] [int] NOT NULL,
	[CreateDate] [datetime] NOT NULL,
	[ChangedBy] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[ContactGuid] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_TR_CONTACT_1] PRIMARY KEY CLUSTERED 
(
	[ContactGuid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_DATAORIGIN]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_DATAORIGIN]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_DATAORIGIN](
	[DataOrigin] [int] NOT NULL,
	[OriginDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_DATAORIGIN] PRIMARY KEY CLUSTERED 
(
	[DataOrigin] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_EMAIL]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_EMAIL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_EMAIL](
	[EMailId] [int] NOT NULL,
	[PartnerEMail] [varchar](200) NOT NULL,
	[AddressType] [int] NOT NULL,
	[CreatedBy] [int] NOT NULL,
	[CreateDate] [datetime] NOT NULL,
	[ChangedBy] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[PartnerGuid] [uniqueidentifier] NOT NULL,
 CONSTRAINT [pk_email] PRIMARY KEY CLUSTERED 
(
	[EMailId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_NOTE]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_NOTE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_NOTE](
	[NoteId] [int] NOT NULL,
	[NoteSource] [int] NOT NULL,
	[NoteType] [int] NULL,
	[NoteText] [varchar](max) NOT NULL,
	[CreatedBy] [int] NOT NULL,
	[CreateDate] [datetime] NOT NULL,
	[ChangedBy] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[SourceGuid] [uniqueidentifier] NOT NULL,
 CONSTRAINT [pk_note] PRIMARY KEY CLUSTERED 
(
	[NoteId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[TR_NOTETYPE]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_NOTETYPE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_NOTETYPE](
	[NoteType] [int] NOT NULL,
	[TypeDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_NOTETYPE] PRIMARY KEY CLUSTERED 
(
	[NoteType] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_OPPORTUNITYH]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYH]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_OPPORTUNITYH](
	[OpportunityId] [int] NOT NULL,
	[Description] [varchar](200) NOT NULL,
	[OppType] [int] NOT NULL,
	[OppRevenue] [float] NULL,
	[Probability] [int] NULL,
	[TotalRevenue] [float] NULL,
	[TotalQuantity] [int] NULL,
	[CloseDate] [datetime] NULL,
	[MileStoneDate] [datetime] NULL,
	[Status] [int] NOT NULL,
	[Application] [varchar](50) NULL,
	[OppStage] [int] NULL,
	[Competitor] [varchar](50) NULL,
	[DealStatus] [int] NOT NULL,
	[ResellerNo] [int] NULL,
	[OppReferral] [int] NULL,
	[OppGuid] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_TR_OPPORTUNITYH_1] PRIMARY KEY CLUSTERED 
(
	[OppGuid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_OPPORTUNITYI]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYI]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_OPPORTUNITYI](
	[OpportunityId] [int] NOT NULL,
	[ProductId] INT NOT NULL,
	[Quantity] [int] NOT NULL,
	[CustomPrice] [float] NULL,
	[OppGuid] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_TR_OPPORTUNITYI_1] PRIMARY KEY CLUSTERED 
(
	[ProductId] ASC,
	[OppGuid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_OPPREFERRAL]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_OPPREFERRAL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_OPPREFERRAL](
	[OppReferral] [int] NOT NULL,
	[ReferralDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_OPPREFERRAL] PRIMARY KEY CLUSTERED 
(
	[OppReferral] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_OPPSTAGE]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_OPPSTAGE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_OPPSTAGE](
	[OppStage] [int] NOT NULL,
	[StageDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_OPPSTAGE] PRIMARY KEY CLUSTERED 
(
	[OppStage] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_OPPTYPE]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_OPPTYPE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_OPPTYPE](
	[OppType] [int] NOT NULL,
	[TypeDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_OPPTYPE] PRIMARY KEY CLUSTERED 
(
	[OppType] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_PARTNER]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_PARTNER](
	[PartnerNo] [int] NOT NULL,
	[PartnerGuid] [uniqueidentifier] NOT NULL,
	[PartnerCategory] [int] NOT NULL,
	[PartnerType] [int] NOT NULL,
	[PartnerName] [varchar](200) NULL,
	[PartnerLastName] [varchar](200) NULL,
	[PartnerFirstName] [varchar](200) NULL,
	[PartnerDivision] [int] NOT NULL,
	[AccountGroup] [int] NULL,
	[DataOrigin] [int] NULL,
	[Vertical] [int] NULL,
	[isActive] [bit] NOT NULL,
	[CreatedBy] [int] NOT NULL,
	[CreateDate] [datetime] NOT NULL,
	[ChangedBy] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
	[Website] [varchar](200) NULL,
	[WebsiteDesc] [varchar](200) NULL,
	[NoofLocations] [int] NULL,
 CONSTRAINT [PK_TR_PARTNER] PRIMARY KEY CLUSTERED 
(
	[PartnerGuid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_PARTNERCATEGORY]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_PARTNERCATEGORY]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_PARTNERCATEGORY](
	[PartnerCategory] [int] NOT NULL,
	[CategoryDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_PARTNERCATEGORY] PRIMARY KEY CLUSTERED 
(
	[PartnerCategory] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_PARTNERDIVISION]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_PARTNERDIVISION]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_PARTNERDIVISION](
	[PartnerDivision] [int] NOT NULL,
	[DivisionDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_PARTNERDIVISION] PRIMARY KEY CLUSTERED 
(
	[PartnerDivision] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_PARTNERTYPE]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_PARTNERTYPE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_PARTNERTYPE](
	[PartnerType] [int] NOT NULL,
	[TypeDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_PARTNERTYPE] PRIMARY KEY CLUSTERED 
(
	[PartnerType] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_PRODUCT]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_PRODUCT]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_PRODUCT](
	[ProductId] INT NOT NULL,
	[ProductNo] [varchar](50) NULL,
	[ProductDesc] [varchar](200) NULL,
	[UnitPrice] [float] NOT NULL,
	[isActive] [bit] NOT NULL,
 CONSTRAINT [PK_TR_PRODUCT] PRIMARY KEY CLUSTERED 
(
	[ProductId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_RELATIONSHIPS]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_RELATIONSHIPS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_RELATIONSHIPS](
	[RelationshipId] [int] NOT NULL,
	[SourceGuid] [uniqueidentifier] NOT NULL,
	[Partner2] [int] NOT NULL,
	[IsMain] [bit] NULL,
	[RelationshipType] [int] NOT NULL,
	[CreatedBy] [int] NOT NULL,
	[CreateDate] [datetime] NOT NULL,
	[ChangedBy] [int] NOT NULL,
	[ChangeDate] [datetime] NOT NULL,
 CONSTRAINT [PK_TR_RELATIONSHIPS] PRIMARY KEY CLUSTERED 
(
	[RelationshipId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Table [dbo].[TR_RELATIONTYPE]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_RELATIONTYPE]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_RELATIONTYPE](
	[RelationshipType] [int] NOT NULL,
	[TypeDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_RELATIONTYPE] PRIMARY KEY CLUSTERED 
(
	[RelationshipType] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_STATES]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_STATES]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_STATES](
	[State] [varchar](10) NOT NULL,
	[StateDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_STATES] PRIMARY KEY CLUSTERED 
(
	[State] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_STATUS]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_STATUS]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_STATUS](
	[Status] [int] NOT NULL,
	[StatusDesc] [varchar](200) NOT NULL,
	[StatusProfile] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_STATUS] PRIMARY KEY CLUSTERED 
(
	[Status] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_USER]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_USER]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_USER](
	[PartnerNo] [int] NOT NULL,
	[LoginId] [varchar](100) NOT NULL,
	[Password] [varchar](100) NOT NULL,
	[CanCreateParentAcct] [bit] NOT NULL,
	[CanEditProductMaster] [bit] NOT NULL,
	[ManagerId] [int] NULL,
	[isSuperUser] [bit] NOT NULL,
	[isActive] [bit] NOT NULL,
	[PartnerGuid] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_TR_USER] PRIMARY KEY CLUSTERED 
(
	[PartnerGuid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[TR_VERTICAL]    Script Date: 04/24/2009 23:40:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TR_VERTICAL]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TR_VERTICAL](
	[Vertical] [int] NOT NULL,
	[VerticalDesc] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TR_VERTICAL] PRIMARY KEY CLUSTERED 
(
	[Vertical] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_PADDING OFF
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_ACTIVITYTASK_TR_ACTIVITYTYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_ACTIVITYTASK]'))
ALTER TABLE [dbo].[TR_ACTIVITYTASK]  WITH CHECK ADD  CONSTRAINT [FK_TR_ACTIVITYTASK_TR_ACTIVITYTYPE] FOREIGN KEY([ActivityType])
REFERENCES [dbo].[TR_ACTIVITYTYPE] ([ActivityType])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_ACTIVITYTASK_TR_STATUS]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_ACTIVITYTASK]'))
ALTER TABLE [dbo].[TR_ACTIVITYTASK]  WITH CHECK ADD  CONSTRAINT [FK_TR_ACTIVITYTASK_TR_STATUS] FOREIGN KEY([Status])
REFERENCES [dbo].[TR_STATUS] ([Status])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_ADDRESS_TR_ADDRESSTYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_ADDRESS]'))
ALTER TABLE [dbo].[TR_ADDRESS]  WITH CHECK ADD  CONSTRAINT [FK_TR_ADDRESS_TR_ADDRESSTYPE] FOREIGN KEY([AddressType])
REFERENCES [dbo].[TR_ADDRESSTYPE] ([AddressType])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_ADDRESS_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_ADDRESS]'))
ALTER TABLE [dbo].[TR_ADDRESS]  WITH CHECK ADD  CONSTRAINT [FK_TR_ADDRESS_TR_PARTNER] FOREIGN KEY([PartnerGuid])
REFERENCES [dbo].[TR_PARTNER] ([PartnerGuid])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_ADDRESS_TR_STATES]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_ADDRESS]'))
ALTER TABLE [dbo].[TR_ADDRESS]  WITH CHECK ADD  CONSTRAINT [FK_TR_ADDRESS_TR_STATES] FOREIGN KEY([State])
REFERENCES [dbo].[TR_STATES] ([State])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_COMMUNICATION_TR_ADDRESS]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_COMMUNICATION]'))
ALTER TABLE [dbo].[TR_COMMUNICATION]  WITH CHECK ADD  CONSTRAINT [FK_TR_COMMUNICATION_TR_ADDRESS] FOREIGN KEY([AddressGuid])
REFERENCES [dbo].[TR_ADDRESS] ([AddressGuid])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_CONTACT_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_CONTACT]'))
ALTER TABLE [dbo].[TR_CONTACT]  WITH CHECK ADD  CONSTRAINT [FK_TR_CONTACT_TR_PARTNER] FOREIGN KEY([ContactGuid])
REFERENCES [dbo].[TR_PARTNER] ([PartnerGuid])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_EMAIL_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_EMAIL]'))
ALTER TABLE [dbo].[TR_EMAIL]  WITH CHECK ADD  CONSTRAINT [FK_TR_EMAIL_TR_PARTNER] FOREIGN KEY([PartnerGuid])
REFERENCES [dbo].[TR_PARTNER] ([PartnerGuid])
GO
--IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_NOTE_TR_ACTIVITYTASK]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_NOTE]'))
--ALTER TABLE [dbo].[TR_NOTE]  WITH CHECK ADD  CONSTRAINT [FK_TR_NOTE_TR_ACTIVITYTASK] FOREIGN KEY([SourceGuid])
--REFERENCES [dbo].[TR_ACTIVITYTASK] ([ActivityTaskGuid])
--GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_NOTE_TR_NOTETYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_NOTE]'))
ALTER TABLE [dbo].[TR_NOTE]  WITH CHECK ADD  CONSTRAINT [FK_TR_NOTE_TR_NOTETYPE] FOREIGN KEY([NoteType])
REFERENCES [dbo].[TR_NOTETYPE] ([NoteType])
GO
--IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_NOTE_TR_OPPORTUNITYH]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_NOTE]'))
--ALTER TABLE [dbo].[TR_NOTE]  WITH CHECK ADD  CONSTRAINT [FK_TR_NOTE_TR_OPPORTUNITYH] FOREIGN KEY([SourceGuid])
--REFERENCES [dbo].[TR_OPPORTUNITYH] ([OppGuid])
--GO
--IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_NOTE_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_NOTE]'))
--ALTER TABLE [dbo].[TR_NOTE]  WITH CHECK ADD  CONSTRAINT [FK_TR_NOTE_TR_PARTNER] FOREIGN KEY([SourceGuid])
--REFERENCES [dbo].[TR_PARTNER] ([PartnerGuid])
--GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYH_TR_OPPREFERRAL]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYH]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYH]  WITH CHECK ADD  CONSTRAINT [FK_TR_OPPORTUNITYH_TR_OPPREFERRAL] FOREIGN KEY([OppReferral])
REFERENCES [dbo].[TR_OPPREFERRAL] ([OppReferral])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYH_TR_OPPSTAGE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYH]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYH]  WITH CHECK ADD  CONSTRAINT [FK_TR_OPPORTUNITYH_TR_OPPSTAGE] FOREIGN KEY([OppStage])
REFERENCES [dbo].[TR_OPPSTAGE] ([OppStage])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYH_TR_OPPTYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYH]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYH]  WITH CHECK ADD  CONSTRAINT [FK_TR_OPPORTUNITYH_TR_OPPTYPE] FOREIGN KEY([OppType])
REFERENCES [dbo].[TR_OPPTYPE] ([OppType])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYH_TR_STATUS]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYH]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYH]  WITH CHECK ADD  CONSTRAINT [FK_TR_OPPORTUNITYH_TR_STATUS] FOREIGN KEY([Status])
REFERENCES [dbo].[TR_STATUS] ([Status])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYI_TR_OPPORTUNITYH]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYI]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYI]  WITH CHECK ADD  CONSTRAINT [FK_TR_OPPORTUNITYI_TR_OPPORTUNITYH] FOREIGN KEY([OppGuid])
REFERENCES [dbo].[TR_OPPORTUNITYH] ([OppGuid])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_OPPORTUNITYI_TR_PRODUCT]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_OPPORTUNITYI]'))
ALTER TABLE [dbo].[TR_OPPORTUNITYI]  WITH CHECK ADD  CONSTRAINT [FK_TR_OPPORTUNITYI_TR_PRODUCT] FOREIGN KEY([ProductId])
REFERENCES [dbo].[TR_PRODUCT] ([ProductId])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_ACCTGROUP]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER]  WITH CHECK ADD  CONSTRAINT [FK_TR_PARTNER_TR_ACCTGROUP] FOREIGN KEY([AccountGroup])
REFERENCES [dbo].[TR_ACCTGROUP] ([AccountGroup])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_DATAORIGIN]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER]  WITH CHECK ADD  CONSTRAINT [FK_TR_PARTNER_TR_DATAORIGIN] FOREIGN KEY([DataOrigin])
REFERENCES [dbo].[TR_DATAORIGIN] ([DataOrigin])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_PARTNERCATEGORY]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER]  WITH CHECK ADD  CONSTRAINT [FK_TR_PARTNER_TR_PARTNERCATEGORY] FOREIGN KEY([PartnerCategory])
REFERENCES [dbo].[TR_PARTNERCATEGORY] ([PartnerCategory])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_PARTNERDIVISION]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER]  WITH CHECK ADD  CONSTRAINT [FK_TR_PARTNER_TR_PARTNERDIVISION] FOREIGN KEY([PartnerDivision])
REFERENCES [dbo].[TR_PARTNERDIVISION] ([PartnerDivision])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_PARTNERTYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER]  WITH CHECK ADD  CONSTRAINT [FK_TR_PARTNER_TR_PARTNERTYPE] FOREIGN KEY([PartnerType])
REFERENCES [dbo].[TR_PARTNERTYPE] ([PartnerType])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_PARTNER_TR_VERTICAL]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_PARTNER]'))
ALTER TABLE [dbo].[TR_PARTNER]  WITH CHECK ADD  CONSTRAINT [FK_TR_PARTNER_TR_VERTICAL] FOREIGN KEY([Vertical])
REFERENCES [dbo].[TR_VERTICAL] ([Vertical])
GO
--IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_RELATIONSHIPS_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_RELATIONSHIPS]'))
--ALTER TABLE [dbo].[TR_RELATIONSHIPS]  WITH CHECK ADD  CONSTRAINT [FK_TR_RELATIONSHIPS_TR_PARTNER] FOREIGN KEY([SourceGuid])
--REFERENCES [dbo].[TR_PARTNER] ([PartnerGuid])
--GO
--IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_RELATIONSHIPS_TR_PARTNER1]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_RELATIONSHIPS]'))
--ALTER TABLE [dbo].[TR_RELATIONSHIPS]  WITH CHECK ADD  CONSTRAINT [FK_TR_RELATIONSHIPS_TR_PARTNER1] FOREIGN KEY([SourceGuid])
--REFERENCES [dbo].[TR_PARTNER] ([PartnerGuid])
--GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_RELATIONSHIPS_TR_RELATIONTYPE]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_RELATIONSHIPS]'))
ALTER TABLE [dbo].[TR_RELATIONSHIPS]  WITH CHECK ADD  CONSTRAINT [FK_TR_RELATIONSHIPS_TR_RELATIONTYPE] FOREIGN KEY([RelationshipType])
REFERENCES [dbo].[TR_RELATIONTYPE] ([RelationshipType])
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_TR_USER_TR_PARTNER]') AND parent_object_id = OBJECT_ID(N'[dbo].[TR_USER]'))
ALTER TABLE [dbo].[TR_USER]  WITH CHECK ADD  CONSTRAINT [FK_TR_USER_TR_PARTNER] FOREIGN KEY([PartnerGuid])
REFERENCES [dbo].[TR_PARTNER] ([PartnerGuid])
GO
